package com.example.springboot.demo.resource;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;

public class ResourcePath {
    public static void main(String[] args) {
//        String pkgName = "com.yix.validate";
//        ClassLoader loader = Thread.currentThread().getContextClassLoader();
//        try {
//            String resourceName = pkgName.replaceAll("\\.", "/").replaceAll("\\*{2,}", "*");
//            Enumeration urls = loader.getResources(resourceName);
//            while(urls.hasMoreElements()) {
//                URL url = (URL)urls.nextElement();
//                if("file".equals(url.getProtocol())){
//                    File file = new File(url.getPath());
//                    System.out.println(file.exists());
//                    for(File file1:file.listFiles()){
//                        System.out.println(file1.exists());
//                        System.out.println(file1.isFile());
//                        System.out.println(file1.getName());
//                    }
//                }
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


        String resourcePath = "static/bgsq_gcl_xchsyj.docx";
        URL systemResource = ClassLoader.getSystemResource(resourcePath);
        System.out.println(">>>" + systemResource);
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(">>>>>" + systemClassLoader.toString());
        System.out.println(">>>" + systemClassLoader.getResource(resourcePath));
        ClassLoader cuurentThreadClassLoader = Thread.currentThread().getContextClassLoader();
        System.out.println(">>>>>" + cuurentThreadClassLoader.toString());
        System.out.println(">>>" + cuurentThreadClassLoader.getResource(resourcePath));
        ClassLoader parentClassLoader = cuurentThreadClassLoader.getParent();
        System.out.println("parent:" + parentClassLoader);
        ClassLoader thisClassLoader = ResourcePath.class.getClassLoader();
        System.out.println("this:" + thisClassLoader);

    }
}
